#include <bits/stdc++.h>
using namespace std;

inline int get_num() {
    int k = 0, f = 1;
    char c = getchar();
    for(; !isdigit(c); c = getchar()) if(c == '-') f = -1;
    for(; isdigit(c); c = getchar()) k = k * 10 + c -'0';
    return k * f;
}

int T;
int d[4][2] = {{1, 0}, {0, -1}, {-1, 0}, {0, 1}};
int c;//上3 左2 下1 右0
int x, y;

void z(int a, int b) {
    if(a <= 0 || b <= 0) return;
    x += d[c][0];
    y += d[c][1];
    //printf("%d %d\n", d[c][0], d[c][1]);
    z(a - b, b);
    c++;
    c %= 4;
    z(b - a, a);
}

int main() {
    freopen("directly.in", "r", stdin);
    freopen("directly.out", "w", stdout);
    T = get_num();
    while(T--) {
        c = 3;
        int a = get_num();
        int b = get_num();
        z(a, b);
        printf("%d %d\n", x, y);
        x = 0;
        y = 0;
    }
}


